package vip.xls8z.lfi.listener;

import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.context.event.ContextStoppedEvent;
import org.springframework.stereotype.Component;

@Component
public class ApplicationEventListener implements ApplicationListener<ApplicationEvent> {
    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        if (event instanceof ApplicationEnvironmentPreparedEvent) {
            println("环境初始化.");
        }
        else if (event instanceof ApplicationPreparedEvent) {
            println("初始化完成.");
        }
        else if (event instanceof ContextRefreshedEvent) {
            println("应用刷新.");
        }
        else if (event instanceof ApplicationReadyEvent) {
            println("项目启动完成.");
        }
        else if (event instanceof ContextStartedEvent) {
            println("应用启动.");
        }
        else if (event instanceof ContextStoppedEvent) {
            println("项目中止.");
        }
        else if (event instanceof ContextClosedEvent) {
            println("应用关闭.");
        }
    }

    public void println(String message) {
        System.out.println(message);
    }
}
